package gui;

import launch.SimpleTest;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.RoundedRectangle;
import org.newdawn.slick.thingle.Page;
import org.newdawn.slick.thingle.Widget;
import org.newdawn.slick.thingle.spi.ThingleException;

import character.Hero;

/**
 * Affiche une bulle de dialogue au dessus du personnage
 * @author Kent
 *
 */
public class GUIDialog extends GUIEvent {

	private String message;
	private Color color_message;
	private Color background;
	
	/**
	 * Constructeur
	 * @param m : le message
	 * @param dialoger : le personnage qui parle
	 * @param col_m : la couleur du texte
	 * @param backg : la couleur du fond
	 */
	public GUIDialog(String m,Hero dialoger,Color col_m,Color backg,int startAt){
		super(dialoger.getCameraX() + 30,dialoger.getCameraY() - 50,startAt);
		message = m;
		color_message = col_m;
		background = backg;
	}
	
	/**
	 * Genere et affiche le message
	 */
	@Override
	public void render(Graphics g){
		Color originalcolor = g.getColor();
		int size = getTextWidth(message,SimpleTest.app.getDefaultFont());
		RoundedRectangle rr = new RoundedRectangle(x,y,size,40,50f);
		
		g.setColor(background);
		g.fillRoundRect(x,y,size+5,40,50);

		g.setColor(color_message);
		g.drawString(message, rr.getMinX() + 5, (rr.getMinY()) + (rr.getHeight()/2) - 10);
		
		g.setColor(originalcolor);		
		try {
			Page page = new Page();
			page.setDrawDesktop(false);
			page.enable();
			Widget button;
			Widget panel = page.parse("<panel  bottom='15' right='15' />");
			button = page.parse("<panel  bottom='15' right='15'> <dialog name='test' columns='1' top='4' weightx='1' weighty='1' "
			         + "text='Select turret alignment method' top='10' modal='true' left='10' "
			         + "bottom='10' right='10' gap='6' valign='bottom' halign='right' /> </panel>");
			panel.add(button);
			page.add(panel);
			page.render();
		} catch (ThingleException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Modifie le message
	 */
	@Override
	public void setString(String m){
		message = m;
	}

}
